package com.martinzhuang.welcomedemo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import java.util.ArrayList;

/**
 * Created by martinzhuang on 7/24/15.
 */
public class GuideView extends Activity implements ViewPager.OnPageChangeListener {

    private ArrayList<View> views;
    private ViewPagerAdapter vpAdapter;
    private ViewPager viewPager;
    private static final int[] pics = {R.drawable.first, R.drawable.second, R.drawable.third, R.drawable.fourth, R.drawable.fiveth};
    private View view1, view2, view3, view4, view5;
    private Button btn_enter;
    private View guide;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //hide action bar
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        //hide navigation bar
        guide = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
        guide.setSystemUiVisibility(uiOptions);

        setContentView(R.layout.guide_activity);
        initView();
        initData();
    }

    private void initView() {
        LayoutInflater layoutInflater = LayoutInflater.from(this);
        view1 = layoutInflater.inflate(R.layout.guide_view01, null);
        view2 = layoutInflater.inflate(R.layout.guide_view02, null);
        view3 = layoutInflater.inflate(R.layout.guide_view03, null);
        view4 = layoutInflater.inflate(R.layout.guide_view04, null);
        view5 = layoutInflater.inflate(R.layout.guide_view05, null);

        views = new ArrayList<View>();
        views.add(view1);
        views.add(view2);
        views.add(view3);
        views.add(view4);
        views.add(view5);

        vpAdapter = new ViewPagerAdapter(views);
        viewPager = (ViewPager) findViewById(R.id.viewpager);

        btn_enter = (Button) view5.findViewById(R.id.btn_enter);
    }

    private void initData() {
//        LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
//        for(int i=0; i<pics.length; i++) {
//            ImageView iv = new ImageView(this);
//            iv.setLayoutParams(mParams);
//            iv.setImageResource(pics[i]);
//            views.add(iv);
//        }

        viewPager.setAdapter(vpAdapter);
        viewPager.setOnPageChangeListener(this);

        btn_enter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(GuideView.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }

//    @Override
//    public void onClick(View view) {
//        int position = (int) view.getTag();
//        if (position < 0 || position > pics.length){
//            return;
//        }
//        viewPager.setCurrentItem(position);
//    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {
    }


}
